var mysql = require('mysql'),
	config = require('../config');
var	connection = mysql.createConnection(config.mysqlConfig),
	pool = mysql.createPool(config.mysqlConfig);

module.exports.conSelectOne = function(query, callback){
	connection.query(query,function(err,row){
		if (err) {
			if (err.code === 'PROTOCOL_CONNECTION_LOST') {
				connect();
			} else {
				console.error(err.stack || err);
			}
		} else {
			connection.end();
			callback(err,row);
		}
	});
}


module.exports.poolSelectOne = function(query, callback){
	pool.getConnection(function(err,Connection){
		if (err) {
			console.log(err);
		} else {
			Connection.query(query, function(err, row){
				if (err) {
					console.log(err);
				} else {
					Connection.release();
					callback(err,row);
				}
			});
		}
		
	});
}
